import React, {Component} from 'react';
import CommentItem from './CommentItem';
import PropTypes from 'prop-types';

import css from './CommentList.less'
class CommentList extends Component {
  static propTypes = {
    comments: PropTypes.array,
    onDeleteComment: PropTypes.func
  }
  static defaultProps = {
    comments: []
  }
  constructor(props) {
    super(props)
  }
  handleDeleteComment(index) {
    if (this.props.onDeleteComment) {
      this.props.onDeleteComment(index)
    }
  }
  render() {
    const comments = this.props.comments;
    return (
      <div className={css['comment-list']}>
        <span className={css.title}>评论列表：</span>
        {
          comments.map((item, index) => {
            return (
              <CommentItem index={index} key={index} comment={item} onDeleteComment={this.handleDeleteComment.bind(this)}></CommentItem>
            )
          })
        }
      </div>
    )
  }
}
export default CommentList;